package com.feri.rbacsys.controller;

import com.feri.rbacsys.service.intf.OrderService;
import com.feri.rbacsys.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @Author:陈琳琳
 */
@Api(tags = "订单接口")
@RestController
@RequestMapping("/api/order/")
public class OrderControlller {
    @Resource
    OrderService service;
    /***
     * 查看未审核的订单dto
     */
    @PreAuthorize("hasAuthority('order:uncheck')")
    @GetMapping("allDto")
    @ApiOperation("未审核订单")
    public R getOrderDto(){
       return service.getAllDto();
    }
    /***
     * 查看订单详情
     */
    @PreAuthorize("hasAuthority('order:uncheckdetail')")
    @GetMapping("detail")
    @ApiOperation("未审核订单详情")
    public R getById(Integer id){
        return service.getOrderDetailDto(id);
    }
    /***
     * 查看订单信息
     */
    @PreAuthorize("hasAuthority('order:detail')")
    @GetMapping("order")
    @ApiOperation("单独订单详情")
    public R getOrder(Integer id){
        return service.getById(id);
    }

    @PostMapping("import")
    @ApiOperation("导入订单")
    public void importFile(@RequestPart MultipartFile file) throws IOException {
        service.importFile(file);
    }


}
